﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading;
using MahApps.Metro.Controls.Dialogs;   //需要安装


namespace wd_7_system_button_closing
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        //private async void DialogBeforeExit()
        //{
        //    //MessageBoxResult ret = await System.Windows.MessageBox.Show("确认？", this.Title, MessageBoxButton.OKCancel);

        //}

        private void MetroWindowClosing(object sender, System.ComponentModel.CancelEventArgs e)
        {            
            //CancellationToken token;
            //TaskScheduler uiSched = TaskScheduler.FromCurrentSynchronizationContext();
            //Task.Factory.StartNew(DialogBeforeExit, token, TaskCreationOptions.None, uiSched);
            if (MessageBoxResult.OK == System.Windows.MessageBox.Show("确认离开？", this.Title, MessageBoxButton.OKCancel))
            {                
                System.Windows.Application.Current.Shutdown();
                //System.Environment.Exit(System.Environment.ExitCode);
            }
            else
            {
                e.Cancel = true;    // key value
                return;
            }
        }
    }
}
